module eth_send_test(
	rst_n				,
	gmii_tx_clk		,
	gmii_tx_en		,
	gmii_tx_er		,
	gmii_tx_data	,
	phy_rst_n				
);

	input rst_n;
	input gmii_tx_clk;
	output gmii_tx_en;
	output gmii_tx_er;
	output [7:0]gmii_tx_data;
	output phy_rst_n;
	
	assign phy_rst_n = 1;
	
	wire fifo_rdreq;
	wire tx_go;
	reg [7:0] fifo_rddata;
	wire fifo_rdclk;
	reg [11:0]data_cnt;
	wire [31:0]CRC_result;
	reg [23:0]cnt;//发送间隔计数器
	
	parameter CRC = 32'hBE7C1CBB; //整个数据包CRC校验值，本例中使用CRC计算软件计算得出
	//调整 CRC校验字字节顺序以符合以太网数据包校验格式（根据其算法进行字节翻转）
	assign CRC_result = {CRC[7:0],CRC[15:8],CRC[23:16],CRC[31:24]};

	eth_send eth_send_inst(
		.rst_n			(rst_n						),
		.tx_go			(tx_go						),
		.data_length	(16'd46						),
		.des_mac			(48'hff_ff_ff_ff_ff_ff	),
		.src_mac			(48'h00_07_ed_ac_62_00	),
		.type_length	(16'h08_06					),
		.CRC_Result		(CRC_result					),
		.fifo_rdreq		(fifo_rdreq					),
		.fifo_rddata	(fifo_rddata				),
		.fifo_rdclk		(fifo_rdclk					),
		.gmii_tx_clk	(gmii_tx_clk				),
		.gmii_tx_en		(gmii_tx_en					),
		.gmii_tx_er		(gmii_tx_er					),
		.gmii_tx_data	(gmii_tx_data				)
	);
	
	always @ (posedge gmii_tx_clk or negedge rst_n)
	if (!rst_n)
		data_cnt <= 12'd0;
	else if (fifo_rdreq)
		data_cnt <= data_cnt + 1'd1;
	else
		data_cnt <= 12'd0;

	//ARP包数据段	
always@(*)
	begin
		case(data_cnt)
			//hdwr type
			00: fifo_rddata =	8'h00;
			01: fifo_rddata =	8'h01;
			
			//protocol type
			02: fifo_rddata =	8'h08;
			03: fifo_rddata =	8'h00;
			
			//hdwr size
			04: fifo_rddata =	8'h06;
			
			//protocol size
			05: fifo_rddata =	8'h04;
			
			//opcode
			06: fifo_rddata =	8'h00;
			07: fifo_rddata =	8'h01;
			
			//sender mac
			08: fifo_rddata =	8'h00;
			09: fifo_rddata =	8'h07;
			10: fifo_rddata =	8'hed;
			11: fifo_rddata =	8'hac;
			12: fifo_rddata =	8'h62;
			13: fifo_rddata =	8'h00;
			
			//sender ip : 192.168.0.2
			14: fifo_rddata =	8'hc0;//192
			15: fifo_rddata =	8'ha8;//168
			16: fifo_rddata =	8'h00;//0
			17: fifo_rddata =	8'h02;//2
			
			//target mac   ARP帧：目的MAC暂时还不知道，发生ARP请求方先将MAC填充0占位
			18: fifo_rddata =	8'h00;
			19: fifo_rddata =	8'h00;
			20: fifo_rddata =	8'h00;
			21: fifo_rddata =	8'h00;
			22: fifo_rddata =	8'h00;
			23: fifo_rddata =	8'h00;
			
			//target ip : 192.168.0.3
			24: fifo_rddata =	8'hc0;//192
			25: fifo_rddata =	8'ha8;//168
			26: fifo_rddata =	8'h00;//0
			27: fifo_rddata =	8'h03;//3
			
			//填充字段，以使整个数据帧长度达到64字节  最小传输帧：为了使数据传输完之前能够收到冲突信号，从而保证数据正确性
			28: fifo_rddata =	8'h00;
			29: fifo_rddata =	8'h00;
			30: fifo_rddata =	8'hff;
			31: fifo_rddata =	8'hff;
			32: fifo_rddata =	8'hff;
			33: fifo_rddata =	8'hff;
			34: fifo_rddata =	8'hff;
			35: fifo_rddata =	8'hff;
			36: fifo_rddata =	8'h00;
			37: fifo_rddata =	8'h23;
			38: fifo_rddata =	8'hcd;
			39: fifo_rddata =	8'h76;
			40: fifo_rddata =	8'h63;
			41: fifo_rddata =	8'h1a;
			42: fifo_rddata =	8'h08;
			43: fifo_rddata =	8'h06;
			44: fifo_rddata =	8'h00;
			45: fifo_rddata =	8'h01;
			default:fifo_rddata = 8'h0;
		endcase
	end
	
always @ (posedge gmii_tx_clk or negedge rst_n)
	if (!rst_n)
		cnt <= 24'd0;
	else 
		cnt <= cnt + 1'd1;
	
	//24位cnt计满一次启动一次发送，该时间大约为134ms
	assign tx_go = (cnt == 24'd1)?1'b1:1'b0; //一帧数据发送标志信号（电平维持一个时钟周期）

endmodule 